﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Speech.Recognition;
using System.Text;

namespace WindowsSpeech
{
    /// <summary>
    /// speech control
    /// </summary>
    public class MySpeechRecognitionEngine
    {
        private SpeechRecognitionEngine SRE;
        public MySpeechRecognitionEngine()
        {
            SRE = new SpeechRecognitionEngine();
        }
        public void SpeechControl()
        {
            SRE.SetInputToDefaultAudioDevice();
            GrammarBuilder GB = new GrammarBuilder();
            GB.Append("选择");
            GB.Append(new Choices(new string[] { "红色", "绿色" }));
            Grammar G = new Grammar(GB);
            G.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(G_SpeechRecognized);
            SRE.LoadGrammar(G);
            SRE.RecognizeAsync(RecognizeMode.Multiple);
        }
        void G_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            if (e.Result.Text.Equals("选择红色"))
            {
                Console.WriteLine("---------------选择红色----------------");
            }
        }
    }
}
